/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package controllers;

import java.awt.Dimension;
import java.awt.event.*;
import javax.swing.UIManager;

import views.*;
import models.*;

/**
 *
 * @author dennis
 */
public class Sokoban{
    
    public GUIFrame guiFrame;
    
    public Menu menu;
    public Game game;
    public Level level;
    
    public GamePanel gamePanel;
    public MenuPanel menuPanel;
    
    public Tile[][] backupmatrix;
    
    /**
     * Creates a new Level, Menu and Game
     */
    public Sokoban(){
      
        level = new Level();  
        guiFrame = new GUIFrame();
        menu = new Menu(this);
        game = new Game(this);
        
    }
    
    /**
     * Adds the gamepanel en menupanel to the frame
     */
    public void init(){
        
        //Position the panels in the GUI
        gamePanel = game.getGamePanel();
        menuPanel = menu.getMenuPanel();
        
        guiFrame.add(gamePanel, java.awt.BorderLayout.CENTER);
        guiFrame.add(menuPanel, java.awt.BorderLayout.EAST);
        guiFrame.pack();
        guiFrame.setVisible(true);
        
    }
    
    /**
     * This is used when we start a new game which does not have a level yet
     */
    public void revalidateGamePanel(){
               
        this.level = new Level();
        this.game = new Game(this);
        
        this.guiFrame.remove(this.gamePanel);
        this.gamePanel = this.game.getGamePanel();
        this.guiFrame.add(this.gamePanel, java.awt.BorderLayout.CENTER);
        this.guiFrame.validate();
        this.gamePanel.requestFocusInWindow();
        
    }
    
    /**
     * This is used when we start a new game with a level
     * @param level 
     */
    public void revalidateGamePanel(String level){

        this.guiFrame.remove(this.gamePanel);
        
        this.level = new Level(level);
        this.level.setDimensions();
        this.game = new Game(this);

        this.guiFrame.remove(this.gamePanel);
        this.gamePanel = this.game.getGamePanel();
        
        this.guiFrame.add(this.gamePanel, java.awt.BorderLayout.CENTER);
        this.guiFrame.pack();
        
        this.guiFrame.validate();
        this.gamePanel.requestFocusInWindow();
        
    }
    
    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {        
        try {
            UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
            new Sokoban().init();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    
    
}
